#include <netfwd.h>
#include <netsocket.h>
#include <netglobal.h>
#include <logger.h>
#include <netreactor.h>
#include <ping.h>

static void signal_handler( int32_t sig )
{
	switch( sig )
	{
	case SIGINT:
		{
			fprintf( stderr, "catch signal SIGINT, server is shutdown\n" );
			NetGlobal::net_reactor().shutdown();
			break;
		}
	}
	return;
}

int32_t main( int32_t argc, char* argv[] )
{
	char		remote_ip[IPBUF_LEN];

	if( 2 > argc )
	{
		fprintf( stderr, "./test remote_ip...\n" );
		return -1;
	}

    int32_t remote_count = argc - 1;

	struct sigaction act;

	act.sa_handler = SIG_IGN;
	sigaction( SIGTERM, &act, NULL );
	sigaction( SIGPIPE, &act, NULL );
	sigaction( SIGHUP,  &act, NULL );
	sigaction( SIGCHLD, &act, NULL );
	sigaction( SIGALRM, &act, NULL );

	act.sa_handler = signal_handler;
	sigemptyset( &act.sa_mask );
	act.sa_flags = 0;
	sigaction( SIGINT, &act, NULL );

	init_dailylog( "ping_test", MsgLogger::ELOGLEVEL_DEBUG );

	Ping ping_test;

	ping_test.start();

    for( int32_t index = 0; index < remote_count; ++index )
	    ping_test.add_ping_target( argv[index+1] );

    sleep( 100 );

	ping_test.stop();

	fini_log();
	return 0;
}

